package com.dong.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dong.beans.ZoneVO;
import com.dong.mybatis.entity.Zone1;
import com.dong.mybatis.entity.Zone2;
import com.dong.mybatis.entity.Zone3;
import com.dong.mybatis.mapper.Zone1Mapper;
import com.dong.mybatis.mapper.Zone2Mapper;
import com.dong.mybatis.mapper.Zone3Mapper;
import jakarta.annotation.Resource;
import org.apache.catalina.valves.JsonAccessLogValve;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RequestMapping("singledata")
@RestController
public class onedataController {
    @Resource
    public Zone1Mapper zone1Mapper;
    @Resource
    public Zone2Mapper zone2Mapper;
    @Resource
    public Zone3Mapper zone3Mapper;
    @GetMapping("one")
    public Map<String,Object> getZone1(){
ZoneVO zoneVO=new ZoneVO();
        ZoneVO zoneVO2=new ZoneVO();

        ZoneVO zoneVO3=new ZoneVO();
       Map<String,Object> zones=new HashMap<>();
        zones.put("th1",zone1Mapper.selectLatest());
        zones.put("th2",zone2Mapper.selectLatest());
        zones.put("th3",zone3Mapper.selectLatest());
        zoneVO.setZones(zones);


            return zones;

        }
    @GetMapping("getZoneall")
    public List<Object> getZoneall(String zoneid)
    {
        QueryWrapper<Zone1> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("time");

        QueryWrapper<Zone2> queryWrapper2 = new QueryWrapper<>();
        queryWrapper.orderByAsc("time");

        QueryWrapper<Zone3> queryWrapper3 = new QueryWrapper<>();
        queryWrapper.orderByAsc("time");
if(zoneid.equals("one")){
    return Collections.singletonList(zone1Mapper.selectList(queryWrapper));
} else if (zoneid.equals("two")) {
    return Collections.singletonList(zone2Mapper.selectList(queryWrapper2));
}else if (zoneid.equals("three")) {
    return Collections.singletonList(zone3Mapper.selectList(queryWrapper3));
}


return null;
    }

    }

